View Javadoc
1 package com.inigoserrano.isvalidator.errorDo; 2 3 import java.util.Enumeration; 4 import java.util.Hashtable; 5 6 /*** 7 * This class is used to process each check that dosnīt match 8 * It is specially designed to work with the Struts framework. 9 * The error message is error.nameOfTheField.IdentifierOfErrorCheck 10 * @license@ 11 * @version @version@ 12 * @author @author@ 13 **/ 14 public class StrutsErrorDo implements ErrorDo { 15 /*** 16 * To store all the parameter of the Check, the data and 17 * the dataGroup 18 */ 19 protected Hashtable parameters = null; 20 21 /*** 22 * Default Constructor 23 **/ 24 public StrutsErrorDo() { 25 super(); 26 } 27 28 /*** 29 * Add one parameter to the store 30 * @param parameterName the name 31 * @param parameterValue the value 32 **/ 33 public void addParameter(String parameterName, String parameterValue) { 34 if (this.parameters == null) { 35 this.parameters = new Hashtable(); 36 } 37 parameters.put(parameterName, parameterValue); 38 } 39 40 /*** 41 * This method return the name of the field (valueToCheckName) 42 * that has the error 43 * @return the name 44 **/ 45 public String getFieldName() { 46 return (String) parameters.get("valueToCheckName"); 47 } 48 49 /*** 50 * Gets the error message is error.nameOfTheField.IdentifierOfErrorCheck 51 * @return the error message 52 * @throws ErrorDoInternalException for internal error only 53 **/ 54 public String getMessage() throws ErrorDoInternalException { 55 //Error check 56 String message = null; 57 if (this.parameters == null) { 58 throw new ErrorDoInternalException( 59 "Parameters is Null, the " 60 + "Constraint must add the parameter to this ErrorDo"); 61 } 62 if (parameters.get("constraint") == null) { 63 throw new ErrorDoInternalException( 64 "The parameter constraints " 65 + "is Null, the Constraint must add the " 66 + "parameter to this ErrorDo"); 67 } 68 message = null; 69 //End Error Check 70 message = 71 "error." 72 + parameters.get("valueToCheckName") 73 + "." 74 + parameters.get("constraint"); 75 return message; 76 } 77 78 /*** 79 * gets a new instace of this class, with all the parameters 80 * @return the new Instance 81 **/ 82 public ErrorDo getNewInstance() { 83 Enumeration iterator = null; 84 String key = null; 85 StrutsErrorDo newInstance = new StrutsErrorDo(); 86 if (this.parameters == null) { 87 return newInstance; 88 } else { 89 iterator = parameters.keys(); 90 while (iterator.hasMoreElements()) { 91 key = (String) iterator.nextElement(); 92 newInstance.addParameter(key, (String) parameters.get(key)); 93 } 94 return newInstance; 95 } 96 } 97 }

This page was automatically generated by Maven